﻿using System.ComponentModel;

namespace Gmantis.Controls.Chart
{
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
    public class ChartSubtype
    {
        // Fields
        private object _conn;
        private string _name;
        private string _rname;
        private string _ropts;
        private object _sym;

        // Methods
        public ChartSubtype()
        {
        }

        internal ChartSubtype(string name, string rend, string rendopts)
        {
            this._name = name;
            this._rname = rend;
            this._ropts = rendopts;
        }

        internal void Apply(Chart chart)
        {
            chart.BeginUpdate();
            IRenderer renderer = chart.Renderers.GetRenderer(this.Renderer);
            if (renderer != null)
            {
                renderer.Options = this.RendererOptions;
                BaseRenderer renderer2 = renderer as BaseRenderer;
                if (renderer2 != null)
                {
                    renderer2.Symbol = this.Symbol;
                    renderer2.Connection = this.Connection;
                }
                if (chart.Data != null)
                {
                    chart.Data.Renderer = renderer;
                    foreach (DataSeries series in chart.Data.Children)
                    {
                        series.ClearDataCache();
                    }
                }
                if ((chart.View != null) && chart.View.Inverted)
                {
                    renderer2.Inverted = !renderer2.Inverted;
                }
            }
            chart.EndUpdate();
        }

        // Properties
        public object Connection
        {
            get
            {
                return this._conn;
            }
            set
            {
                this._conn = value;
            }
        }

        public string Name
        {
            get
            {
                return this._name;
            }
            set
            {
                this._name = value;
            }
        }

        public string Renderer
        {
            get
            {
                return this._rname;
            }
            set
            {
                this._rname = value;
            }
        }

        public string RendererOptions
        {
            get
            {
                return this._ropts;
            }
            set
            {
                this._ropts = value;
            }
        }

        public object Symbol
        {
            get
            {
                return this._sym;
            }
            set
            {
                this._sym = value;
            }
        }
    }
}
